#ifndef _BLOCKBREAKER_MODEL_SCENE_H__
#define _BLOCKBREAKER_MODEL_SCENE_H__

#include <vector>

#include <Model\Include\Block.h>
#include <Model\Include\Ball.h>
#include <Model\Include\Paddle.h>

class Scene
{
public:
    typedef enum
    {
        BALL_IN_SCENE,
        BALL_OUT_OF_SCENE
    }BallStatusType;    
    
    Scene(const float &min_x, const float &max_x, const float &min_y, const float &max_y);
    virtual ~Scene(void);

    void addBlock(Block* block);
    void addBall(Ball* ball);
    void addPaddle(Paddle* paddle);

    std::vector<Block*> getBlocks();
    std::vector<Ball*> getBalls();
    std::vector<Paddle*> getPaddles();

    void removeBall(Ball* block);

    void move(const float &delta_time);
    bool checkBallBlocksCollision(Ball* ball);
    void checkBallPaddlesCollision(Ball* ball);
    BallStatusType checkBallSceneCollision(Ball* ball);
    void checkPaddlesSceneCollision();

    bool hasBlocksLeft();

    float getMinX() const;
    float getMaxX() const;
    float getMinY() const;
    float getMaxY() const;

private:
    float min_x;
    float max_x;
    float min_y;
    float max_y;
    std::vector<Block*> blocks;
    std::vector<Ball*> balls;
    std::vector<Paddle*> paddles;

    typedef enum
    {
        UP,
        DOWN,
        RIGHT,
        LEFT,
        NONE
    }NormalDirectionType;

    NormalDirectionType checkBlockBallCollision(Block* block, Ball* ball);
    bool checkBlockBallCollisionTopBorder(Block* block, Ball* ball);
    bool checkBlockBallCollisionBottomBorder(Block* block, Ball* ball);
    bool checkBlockBallCollisionRightBorder(Block* block, Ball* ball);
    bool checkBlockBallCollisionLeftBorder(Block* block, Ball* ball);
    void bounceBall(Ball* ball, NormalDirectionType normal_type);
    void bounceBallInPaddle(Ball* ball, float position_in_paddle_collided_normalized);
    bool checkCirculeSegmentCollision(  const float &center_x, 
                                        const float &center_y, 
                                        const float &radio, 
                                        const float &x1, 
                                        const float &y1, 
                                        const float &x2, 
                                        const float &y2);
    bool checkCirculeSegmentCollision(  const float &center_x, 
                                        const float &center_y, 
                                        const float &radio, 
                                        const float &x1, 
                                        const float &y1, 
                                        const float &x2, 
                                        const float &y2,
                                        float* t);
};

#endif // _BLOCKBREAKER_MODEL_SCENE_H__
